-
Notifications
You must be signed in to change notification settings - Fork 1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Dev #1
base: master
Are you sure you want to change the base?
Dev #1
Conversation
@@ -0,0 +1,2 @@ | |||
node_module |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this should be node_modules
node_module | |
node_modules | |
@@ -1,24 +1,29 @@ | |||
const crypto = require('crypto'); | |||
const https = require('https'); | |||
require('dotenv').config(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
require('dotenv').config(); | |
const nconf = require('nconf'); |
const apiKey = process.env.API_KEY; | ||
const privateKey = process.env.PRIVATE_KEY; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would suggest using nconf over dotenv, it's far more "12 factor" and a better user experience.
const apiKey = process.env.API_KEY; | |
const privateKey = process.env.PRIVATE_KEY; | |
const ENV_SEPARATOR = '__'; | |
const KEY = 'btcmarkets'; | |
const ENV_PATTERN = new RegExp(`/^${KEY.toUpperCase()}${ENV_SEPARATOR}/`); | |
nconf | |
.env({ | |
separator: ENV_SEPARATOR, | |
match: ENV_PATTERN, | |
lowerCase: true, | |
parseValues: true, | |
transform(obj) { | |
obj.key.replace(ENV_PATTERN, ''); | |
return obj; | |
}, | |
}) | |
.argv({ | |
apiKey: { | |
describe: 'prefix of all new packages created', | |
}, | |
privateKey: { | |
describe: 'prefix of all new packages created', | |
} | |
}); | |
const apiKey = nconf.get('apiKey'); | |
const privateKey = nconf.get('privateKey'); |
Now the cli is used like this:
node client.js --apiKey=something --privateKey=another-thing
or
BTCMARKETS_API_KEY=something \
BTCMARKETS_API_PRIVATE=another-thing \
node client.js
you'll also get :
node client.js --help
No description provided.